/***************************************************************
 * Name:      BootCDCheckerMain.cpp
 * Purpose:   Code for Application Frame
 * Author:    Yang Bo (bob.yang.dev@gmail.com)
 * Created:   2011-02-23
 * Copyright: Yang Bo ()
 * License:
 **************************************************************/

#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__

#include "BootCDCheckerMain.h"
#include <wx/msgdlg.h>
#include "ELTReader.h"

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__WXMAC__)
        wxbuild << _T("-Mac");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
        wxbuild << _T("\nAuthor: Yang Bo (bob.yang.dev@gmail.com)");
    }

    return wxbuild;
}


BootCDCheckerFrame::BootCDCheckerFrame(wxFrame *frame)
    : GUIFrame(frame)
{
#if wxUSE_STATUSBAR
    statusBar->SetStatusText(_("Please Choose 1st CD image."), 0);
    statusBar->SetStatusText(_("Please Choose 2nd CD image."), 1);
#endif
    m_isOpenLeft = true;
}

BootCDCheckerFrame::~BootCDCheckerFrame()
{
}

void BootCDCheckerFrame::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void BootCDCheckerFrame::OnQuit(wxCommandEvent &event)
{
    Destroy();
}

void BootCDCheckerFrame::OnAbout(wxCommandEvent &event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void BootCDCheckerFrame::OnOpen(wxCommandEvent &event)
{
    wxFileDialog dialog
                 (
                    this,
                    _T("Open 1st iso file"),
                    wxEmptyString,
                    wxEmptyString,
                    _T("iso files (*.iso)|*.iso")
                 );

    dialog.SetDirectory(wxGetHomeDir());
    dialog.CentreOnParent();

    if (dialog.ShowModal() == wxID_OK)
    {
		if(m_isOpenLeft)
		{
			m_leftContentPanel->SetCDReader(new ELTReader(dialog.GetPath()));
			#if wxUSE_STATUSBAR
				statusBar->SetStatusText(dialog.GetPath(), 0);
			#endif
		}
		else
		{
			m_rightContentPanel->SetCDReader(new ELTReader(dialog.GetPath()));
			#if wxUSE_STATUSBAR
				statusBar->SetStatusText(dialog.GetPath(), 1);
			#endif
		}
		m_isOpenLeft = !m_isOpenLeft;
    }
}

void BootCDCheckerFrame::OnSize( wxSizeEvent& event )
{
	wxSize newSize = event.GetSize();
	m_splitter3->SetSashPosition(newSize.x/2, true);
	GUIFrame::OnSize(event);
}
